---
import { type CollectionEntry, getCollection } from 'astro:content';
import BlogPost from '../../../layouts/BlogPost.astro';

// const posts = await getCollection('blog');
// type Props = CollectionEntry<'blog'>;
export const prerender = true;

// const { locale, slug } = Astro.params;
// console.log(locale, slug)
// const post = posts.find((page) => { console.log(page.slug); return page.slug === locale + "/" + slug});
// if (!post) return Astro.redirect("/404");
// const { Content } = await post.render();

export async function getStaticPaths() {
	const posts = await getCollection('blog')
	const paths = posts.map(post => {
		const [locale, ...slug] = post.slug.split('/');
		return {
			params: { locale: locale  || 'en', slug: slug.join('/') || 'undefined' }, 
			props: post 
		}
	})

	return paths;
}
type Props = CollectionEntry<'blog'>;

const post = Astro.props;
const { Content } = await post.render();
---

<BlogPost {...post.data}>
	<Content />
</BlogPost>
